package org.example.aop.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;


@Slf4j
@Component
@Aspect
public class MyAspectDemo {

    @Around("@annotation( org.example.aop.config.MyAspect)")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("MyAspectDemo before around...");
        Object object = joinPoint.proceed();
        log.info("MyAspectDemo after around...");
        return object;
    }

    //可以直接注解注释，只要使用这个注释就会执行
    @Around("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public Object Around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("MyAspectDemo before(RequestMapping) around...");
        Object object = joinPoint.proceed();
        log.info("MyAspectDemo after(RequestMapping) around ...");
        return object;

    }

    @Before("@annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public void Before() throws Throwable {
        log.info("MyAspectDemo before(RequestMapping) ...");
    }

}
